#ifndef _H_C_COROUTINE_GROUP_H_
#define _H_C_COROUTINE_GROUP_H_

#include "../typedefine.h"
#include "../threadpool.h"
#include "../collection.h"
#include "../promise.h"
#include <memory>
#include <functional>
#include <atomic>
#include "CCoroutine.h"

namespace TB
{
	class CCoroutineGroupImpl;
	class ICoroutineGroupUserData;

	class CCoroutineGroup
	{
		NON_COPYABLE(CCoroutineGroup)
		NON_MOVEABLE(CCoroutineGroup)
	public:
		CCoroutineGroup(UINT32 dwCoroutineCount, const std::weak_ptr<CThreadPool>& poThreadPool = {});
		~CCoroutineGroup();
		inline void SetUserData(ICoroutineGroupUserData* poUserData) { m_poUserData = poUserData; }
		inline ICoroutineGroupUserData* GetUserData() { return m_poUserData; }
		inline const ICoroutineGroupUserData* GetUserData() const { return m_poUserData; }
		inline void Post(const std::function<void()>& rcbFunction)
		{
			_Post(rcbFunction);
		}
		const std::weak_ptr<CThreadPool>& GetThreadPool() const;
		std::weak_ptr<CThreadPool>& GetThreadPool();

	private:
		void _Post(const std::function<void()>& rcbFunction);

	private:
		std::vector<std::shared_ptr<CCoroutine>> m_oCoroutines;
		std::shared_ptr<CCoroutineGroupImpl> m_poImpl;
		ICoroutineGroupUserData* m_poUserData;
	};
}

#endif
